package com.dubbo.service.impl;

import com.dubbo.common.ResponseUtil;
import com.dubbo.common.page.PageResponse;
import com.dubbo.common.page.PageUtils;
import com.dubbo.domain.User;
import com.dubbo.domain.Wallet;
import com.dubbo.domain.info.ResultMessage;
import com.dubbo.mapper.WalletMapper;
import com.dubbo.service.business.wallet.WalletService;
import com.dubbo.service.impl.base.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 钱包
 * @author lihongwu
 * 2019年1月9日 下午2:26:57
 */
@Service
@Transactional(readOnly = false,rollbackFor=Exception.class)
public class WalletServiceImpl extends BaseServiceImpl<Wallet> implements WalletService {
	
	@Autowired
	private WalletMapper walletMapper;

	 /**
     * 获取代理商加盟金
     *
     * @author lihongwu
     * 2019年1月9日 下午2:31:49
     * @param user
     * @return
     */
	@Override
	public Map<String, Object> getWalletMoney(User user) {
		Map<String, Object> walletMoney = walletMapper.getWalletMoney(user.getId());
		return ResponseUtil.ajaxCheckSuccess(ResultMessage.OK, walletMoney);
	}

	/**
	 * 获取加盟金记录
	 *
	 * @author lihongwu
	 * 2019年1月25日 下午4:51:56
	 * @param user
	 * @return
	 */
	@Override
	public Map<String, Object> getWalletDetail(User user,Long pageStart,Long pageTotal) {
		pageStart = PageUtils.initialPageStart(pageStart);
		pageTotal = PageUtils.initialPageTotal(pageTotal);
		long countPageStart = PageUtils.countPageStart(pageStart, pageTotal);
		
		List<Map<String, Object>> data = walletMapper.getWalletDetail(user.getId(), countPageStart, pageTotal);
		Long pageCount = walletMapper.getWalletDetailCount(user.getId());
		
		return ResponseUtil.ajaxCheckSuccess(ResultMessage.OK, new PageResponse(pageStart, pageTotal, pageCount, data));
	}
	
	
}
